<?php
	
/**
 * Project: CrazyPoems
 * Author: Alexandru
 * Date: 20/10/2008
 * File: functions.login.php
 */
 
function Hop_login($username, $password) {
	global $error_msg, $smarty, $cookie;
	$next = get_next_url();
	if (strlen($next) == 0) { $next = "index.php"; }
	$username = strtolower($username);
	$q = mysql_query("SELECT * FROM ".TABLE_USERS." WHERE username = '$username' and password = '".md5($password)."'") or die(mysql_error());
	$r = mysql_fetch_assoc($q);
	if ($r) {
                $cookie->username = $r['username'];
                $cookie->fullname = $r['fullname'];
                $cookie->email = $r['email'];
                $cookie->admin = $r['admin'];
                $cookie->lang = $r['lang'];
		$smarty->assign('session_username', $r['username']);
		$smarty->assign('session_fullname', $r['fullname']);
		$smarty->assign('session_email', $r['email']);
        $smarty->assign('session_admin', $r['admin']);
		$q2 = mysql_query("UPDATE ".TABLE_USERS." SET last_login = '".get_current_time()."' WHERE id = " . $r['id']) or die(mysql_error());
		header("Location: $next");
		//die($next);
	} else {
		$error_msg .= "<p> Numele de utilizator nu exista sau parola este gresita.</p>";
	}
		
}

?>
